<template>
    <div class="e-form">
        <BillTop title="操作手考核新增" @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="formData.operator" label-width="150px" :rules="rules" >
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="操作手：" prop="operator">
                            <el-input v-model="formData.operator.operator" :readonly="isNameSelect">
                                <i slot="suffix" class="el-input__icon el-icon-document-copy"  @click="selectName"></i>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="联系电话：" prop="phoneNo">
                            <el-input v-model="formData.operator.phoneNo" maxlength="11" :readonly="isNameSelect"
                            v-enter-number="{
                                set: formData,
                                val: 'operator',
                                key: 'phoneNo'
                            }">
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="身份证号：" prop="idCard">
                            <el-input v-model="formData.operator.idCard" :readonly="isNameSelect">
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="性别：" prop="gender">
                            <el-radio-group v-model="formData.operator.gender" :disabled="isNameSelect">
                                <el-radio :label="0">女</el-radio>
                                <el-radio :label="1">男</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="工作状态：" prop="workState">
                            <span>{{formData.operator.workState ? workStatus[formData.operator.workState].label : ''}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="考核时间：" prop="billDate">
                            <el-date-picker
                                v-model="formData.operator.billDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="考核分数：">
                            <span>{{formData.operator.assessmentFraction}}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="考核机构：">
                            <span> {{userInfo.orgInfo.orgName}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose" v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import request from '@/api/equip/operatorManagement.js'
import { mapState, mapMutations } from 'vuex'
import { selectDataClient } from '@/utils/common'
export default {
    data () {
        return {
            formData: {
                operator: {
                    'assessmentFraction': 0,
                    'billDate': '',
                    'billId': '',
                    'founderId': '',
                    'founderName': '',
                    'gender': '',
                    'gmtCreate': '',
                    'gmtModified': '',
                    'idCard': '',
                    'initial': '',
                    'operator': '',
                    'operatorId': '',
                    'orgId': '',
                    'orgName': '',
                    'phoneNo': '',
                    'recorder': '',
                    'recorderId': '',
                    'workState': null
                },
            },
            rules: {
                operator: [
                    { required: true, message: '请选择操作手', trigger: 'change'  },
                ],
                phoneNo: [
                    { required: true, message: '请输入电话', trigger: ['blur', 'change'] },
                ],
                idCard: [
                    { required: true, message: '请输入身份证', trigger: ['blur', 'change'] },
                ],
                gender: [
                    { required: true, message: '请选择性别', trigger: ['blur', 'change'] },
                ],
                workState: [
                    { required: true, message: '请选择工作状态', trigger: 'change' },
                ],
                billDate: [
                    { required: true, message: '请选择考核时间', trigger: 'change' },
                ],
            },
            isNameSelect: true,
        }
    },
    components: {
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            workStatus: state=>state.equip.equipData.workStatus,
            assessmentLevel: state=>state.equip.equipData.assessmentLevel,
        }),
    },
    created () {
    },
    mounted () {
        this.userId = localStorage.getItem('userId')
    },
    methods: {
        ...mapMutations(['setSelectedInfo']),
        //弹窗选择名字
        selectName () {
            let ids = []
            selectDataClient({
                SelectServiceToken: '/facilitybase/operator/assess/get/operator', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: ids, // 已选中id
                Title: '人员选择' // 标题
            }).then(val => {
                this.setSelectedInfo(val)
                this.formData.operator = Object.assign(this.formData.operator, val[0])
                this.formData.operator.billId = ''
                this.formData.operator.orgName = this.userInfo.orgInfo.orgName
                this.formData.operator.orgId = ''
            })
        },
        //保存
        preserve () {
            this.$refs.form.validate(valid => {
                if(valid) {
                    request.operatorAssessAdd(this.formData.operator).then(res=>{
                        this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                            this.$router.push({
                                path: '/operatorAssessEdit',
                                query: {
                                    billid: res,
                                    name: 'records'
                                }
                            })
                        },
                        null,
                        this.handleClose
                        )
                    })
                }else{
                    return false
                }
            })
        },

        //取消
        handleClose () {
            this.$router.replace('/operatorAssessList')
        },
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
